/*
 * Copyright (c) 2007, Nubo Technologies
 *
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
 *
 *    * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
 *    * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
 *    * Neither the name of the Nubo Technologies nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

package com.nubotech.gwt.oss.client.ui;

import com.google.gwt.user.client.ui.FormPanel;
import com.google.gwt.user.client.ui.Panel;
import com.nubotech.gwt.oss.client.*;
import com.nubotech.gwt.oss.client.auth.Credential;
import com.nubotech.gwt.oss.client.s3.S3FileUploadFormPanel;

/**
 *
 * @author jonnakkerud
 */
public abstract class FileUploadFormPanel extends FormPanel {
    private String hostName;
    
    /**
     * Set the Bucket where the file will be uploaded
     * 
     * @param name
     */
    public abstract void setBucketName(String name);    

    /**
     * Set the host name is it is something other then the default. 
     * 
     * @param hostName
     */
    public void setHost(String hostName) {
        this.hostName = hostName;
    }
    
    /**
     * Get the host 
     * 
     * @return
     */
    public String getHost() {
        return this.hostName;
    }
    
    /**
     * Set the AccessPolicy for the file
     * 
     * @param accessPolicy the access policy
     */
    public abstract void setAccessPolicy(int accessPolicy);
    
    /**
     * Set headers like Cache-Control, Content-Type
     * 
     * @param headers
     */
    public abstract void setRequestHeaders(RequestHeader[] headers);

    /**
     * Set the key to location where the file will be uploaded. 
     *
     * @param key
     */
    public abstract void setKey(String key);
    
    /**
     * Security Policy describing what is permitted in the request. 
     * Requests without a security policy are considered anonymous and 
     * only work on publicly writable buckets.
     * 
     * @param policy
     */
    public abstract void setPolicy(SecurityPolicy policy);
    
    /**
     * The URL to which the client is redirected upon successful upload.
     * 
     * @param url
     */
    public abstract void setSuccessActionRedirectUrl(String url);

    /**
     * The status code returned to the client upon successful upload if success_action_redirect is not specified.
     *
     * @param status
     */
    public abstract void setSuccessActionStatus(String status);

    public abstract boolean isUseFileName();

    /**
     * use the file name of the file to be uploaded. If the key is set, then the filename will be 
     * appended to the key.
     * 
     * @param useFileName
     */
    public abstract void setUseFileName(boolean useFileName);
   
    public abstract void setContentTypeFromFile(String fileName);
    
    public static FileUploadFormPanel instance(Panel innerPanel, Credential credential) {
        return new S3FileUploadFormPanel(innerPanel, credential);
    }
    
}
